<template>
  <div class="top">
    <div class="content">
      <!--左侧-->
      <div class="left" @click="goHome">
        <img src="../../assets/vue.svg" alt=""/>
        <p>尚医通</p>
      </div>

      <div class="right">
        <p class="help">帮助中心</p>
        <p @click="login" v-if="!userStore.userInfo?.name">登陆/注册</p>
        <el-dropdown v-else>
          <span class="el-dropdown-link">
            {{userStore.userInfo.name}}
            <el-icon class="el-icon--right">
              <arrow-down/>
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="goUser('/user/certification')">实名认证</el-dropdown-item>
              <el-dropdown-item @click="goUser('/user/order')">挂号订单</el-dropdown-item>
              <el-dropdown-item @click="goUser('/user/patient')">就诊人管理</el-dropdown-item>
              <el-dropdown-item @click="logoutHandler">退出登陆</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import {useRouter} from "vue-router";
import useUserStore from "@/store/modules/user.ts";
import {ArrowDown} from "@element-plus/icons-vue";

const $router = useRouter()
const userStore = useUserStore()
const goHome = () => {
  $router.push('/')
}
const login = () => {
  userStore.visiable = true
}
const logoutHandler = () => {
  userStore.logout()
  $router.push('/')
}
const goUser = (path:string)=>{
  $router.push({
    path
  })
}
</script>

<style lang="scss" scoped>
.top {
  position: fixed;
  z-index: 999;
  width: 100%;
  height: 70px;
  //background: #fff;
  display: flex;
  justify-content: center;

  .content {
    width: $total-width;
    height: 70px;
    background: #fff;
    display: flex;
    justify-content: space-between;

    .left {
      display: flex;
      align-items: center;
      justify-content: center;

      img {
        width: 50px;
        height: 50px;
        margin-right: 10px;
      }

      p {
        font-size: 22px;
        color: #55a6fe;
      }
    }

    .right {
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 16px;
      color: #aaa;
      .help {
        margin-right: 10px;
      }
      .el-dropdown-link{
        outline: none;
      }
    }
  }
}
</style>
